package com.reagent.system.controller;


import com.reagent.system.entity.Goods;
import com.reagent.system.service.GoodsService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@ApiResponses({
        @ApiResponse(code = 200, message = "成功"),
        @ApiResponse(code = 201, message = "成功创建资源"),
        @ApiResponse(code = 400, message = "失败"),
        @ApiResponse(code = 401, message = "服务器认证失败"),
        @ApiResponse(code = 403, message = "资源不存在"),
        @ApiResponse(code = 404, message = "页面不存在"),
        @ApiResponse(code = 500, message = "服务器异常")
})
@Slf4j
@RestController
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @ApiOperation(value = "添加商品", notes = "添加商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "images", value = "商品图片", paramType = "query", dataType = "MultipartFile"),
            @ApiImplicitParam(name = "goods", value = "商品信息", paramType = "query", dataType = "Goods")
    })
    @PostMapping("/addGoods")
    public Object addGoods(MultipartFile image, Goods goods) throws Exception {
        return goodsService.addGoods(image, goods);
    }

    @ApiOperation(value = "获取商品信息", notes = "分页获取商家申请列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "currentPage", value = "当前页", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "serachInfo", value = "查询信息", paramType = "query", dataType = "String")
    })
    @GetMapping("/getGoodsInfoUid")
    public Object getGoodsInfoUid(Integer pageSize, Integer currentPage, String serachInfo) {
        return goodsService.getGoodsInfoUid(pageSize, currentPage, serachInfo);
    }

    @GetMapping("/getGoodsInfo")
    public Object getGoodsInfo(Integer pageSize, Integer currentPage, String serachInfo) {
        return goodsService.getGoodsInfo(pageSize, currentPage, serachInfo);
    }

    @ApiOperation(value = "上架", notes = "上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "修改对象", paramType = "query", dataType = "String"),
    })
    @PatchMapping("/updateStatus1/{id}")
    public Object updateStatus1(@PathVariable("id") Integer id) {
        return goodsService.updateStatus1(id);
    }


    @ApiOperation(value = "下架", notes = "下架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "修改对象", paramType = "query", dataType = "String"),
    })
    @PatchMapping("/updateStatus0/{id}")
    public Object updateStatusToSuccess0(@PathVariable("id") Integer id) {
        return goodsService.updateStatus0(id);
    }
}

